SOURCES = vec3d.ml vec2d.ml matrice.ml mesh.ml driver.ml node.ml camera.ml scene.ml core.ml

NAME = camEngine

PATHOUT = ../lib

LIBOUT = $(PATHOUT)/$(NAME)

CAMLC = ocamlc
CAMLOPT = ocamlopt
CAMLDEP = ocamldep
CAMLLEX = ocamllex
CAMLYACC = ocamlyacc

WITHGRAPHICS =graphics.cma -cclib -lgraphics -cclib -L/usr/X11R6/lib -cclib -lX11
WITHUNIX =unix.cma -cclib -lunix
WITHSTR =str.cma -cclib -lstr
WITHNUMS =nums.cma -cclib -lnums
WITHTHREADS =threads.cma -cclib -lthreads
WITHDBM =dbm.cma -cclib -lmldbm -cclib -lndbm

LIBS=$(WITHGRAPHICS) $(WITHUNIX)

CUSTOM=-custom

all: depend $(LIBOUT).a $(LIBOUT).cmxa $(LIBOUT).cma $(LIBOUT).cmi

$(LIBOUT).cmi: $(NAME).cmi
	cp $(NAME).cmi $@
	
$(LIBOUT).a: $(NAME).cmxa
	cp $(NAME).a $@

$(LIBOUT).cmxa: $(NAME).cmxa
	cp $< $@

$(LIBOUT).cma: $(NAME).cma
	cp $< $@
	
opt : $(EXEC).cmxa

SOURCES1 = $(SOURCES:.mly=.ml)
SOURCES2 = $(SOURCES1:.mll=.ml)
OBJS = $(SOURCES2:.ml=.cmo)
OPTOBJS = $(SOURCES2:.ml=.cmx)

$(NAME).cma: $(NAME).cmo
	$(CAMLC) -a $(CUSTOM) -o $@ $(LIBS) $<

$(NAME).cmo: $(OBJS)
	$(CAMLC) -pack -o $@ $^

$(NAME).cmxa: $(NAME).cmx
	$(CAMLOPT) -a -o $@  $^

$(NAME).cmx: $(OPTOBJS)
	$(CAMLOPT) -pack -o $@ $^

.SUFFIXES: .ml .mli .cmo .cmi .cmx .mll .mly

.ml.cmo:
	$(CAMLC) -g -c $<

.mli.cmi:
	$(CAMLC) -g -c $<

.ml.cmx:
	$(CAMLOPT) -g -for-pack CamEngine -c $<

clean:
	rm -f *.cm[iox] *~ .*~ *.o #*#

realclean: clean
	rm -f $(NAME).a
	rm -f $(NAME).cma
	rm -f $(NAME).cmi
	rm -f $(NAME).cmxa
	rm -f $(LIBOUT).a
	rm -f $(LIBOUT).cma
	rm -f $(LIBOUT).cmi
	rm -f $(LIBOUT).cmxa

.depend: $(SOURCES2)
	$(CAMLDEP) *.mli *.ml > .depend

depend: $(SOURCES2)
	$(CAMLDEP) *.mli *.ml > .depend

include .depend

